home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Operator overload problem!
- Date: Thu, 21 Mar 1996 16:07:26 -0500
- Organization: Datalytics, Inc
- Message-ID: <3151C50E.6A3@datalytics.com>
- References: <DoIn1z.Gou@latcs1.lat.oz.au>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Gregary J Boyles wrote:
- >
- > I am trying to overload the << but I get the syntax errors : friends must be functions or
- > classes, 'ostream' cannot start a parameter declaration, 'Address::operator <<(int &,Address &)'
- > must be declared at the first set of astericks and declaration syntax error at the second set.
- >
- > What the #$%& is it on about? I copied the operator overload function directly out of a program
- > which compiles and runs so why all of a sudden won't the bloody compiler accept it?
- > [snip]
- > * friend ostream& operator <<(ostream& OutPutStream,Address& AnAddress); *
-
- The compiler is simply not explaining itself well. The error
- message sounds like one from Microsoft Visual C++. The problem
- is that you haven't declared ostream at the time you make
- reference to it.
-
- Neither your header nor your .cpp file #include's iostream.h.
- Ideally, you would forward declare ostream in the header, like
- this:
-
- class ostream;
-
- class Address
- {
- ...
-
- and then #include iostream.h in your .cpp file.
-
- This will incompletely, but sufficiently, declare ostream in
- your header, and will completely declare it in your .cpp file.
- The advantage is one of compilation speed. Files #include'ing
- address.h won't pay the penalty of #include'ing iostream.h too.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-